/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * aPlanificacion.java
 *
 * Created on 12-jul-2012, 0:16:32
 */

package interfaz;

import javax.swing.JOptionPane;
import Clases.Planificacion;
import Controladores.PlanificacionPersonalizada;
import escuela.conexion;
import Controladores.PlanificacionJpaController;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
/**
 *
 * @author Bryan
 * En este formulario se administra la planificacion que
 * implementeara cada una de la unidades que posea
 * la escuela
 */
public class aPlanificacion extends javax.swing.JDialog {

     conexion cnx = conexion.ObtenerInstancia();
     EntityManagerFactory emf = cnx.ObtenerEMF();
     PlanificacionPersonalizada plan = new PlanificacionPersonalizada(emf);
     
    /** Creates new form aPlanificacion */
    public aPlanificacion(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        cargardatos();
        }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        nota = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        zona = new javax.swing.JTextField();
        examenfinal = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        examenparcial = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        otras = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        editar = new javax.swing.JButton();
        aceptar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jTaskPane1 = new com.l2fprod.common.swing.JTaskPane();
        jLabel11 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Planificacion");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Características de los cursos"));

        jLabel1.setText("Nota de aprobación");

        nota.setEnabled(false);
        nota.setName("pnota"); // NOI18N
        nota.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                notaActionPerformed(evt);
            }
        });

        jLabel2.setText("Zona");

        zona.setEnabled(false);
        zona.setName("pzona"); // NOI18N
        zona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zonaActionPerformed(evt);
            }
        });

        examenfinal.setEnabled(false);
        examenfinal.setName("pfinal"); // NOI18N
        examenfinal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                examenfinalActionPerformed(evt);
            }
        });

        jLabel3.setText("Examen final");

        jLabel4.setText("Examen parcial");

        examenparcial.setEnabled(false);
        examenparcial.setName("pparcial"); // NOI18N
        examenparcial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                examenparcialActionPerformed(evt);
            }
        });

        jLabel5.setText("Otras tareas");

        otras.setEnabled(false);
        otras.setName("potras"); // NOI18N
        otras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                otrasActionPerformed(evt);
            }
        });

        jLabel6.setForeground(new java.awt.Color(255, 51, 51));
        jLabel6.setText("*");

        jLabel7.setForeground(new java.awt.Color(255, 51, 51));
        jLabel7.setText("*");

        jLabel8.setForeground(new java.awt.Color(255, 51, 51));
        jLabel8.setText("*");

        jLabel9.setForeground(new java.awt.Color(255, 51, 51));
        jLabel9.setText("*");

        jLabel10.setForeground(new java.awt.Color(255, 51, 51));
        jLabel10.setText("*");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(nota, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(zona, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(examenfinal, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(examenparcial, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(otras, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)))))
                .addContainerGap(22, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel6)
                    .addComponent(nota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel7)
                    .addComponent(zona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel8)
                    .addComponent(examenfinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jLabel9))
                    .addComponent(examenparcial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jLabel10))
                    .addComponent(otras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21))
        );

        editar.setText("Editar");
        editar.setName("peditar"); // NOI18N
        editar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                editarMouseClicked(evt);
            }
        });
        editar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarActionPerformed(evt);
            }
        });

        aceptar.setText("Aceptar");
        aceptar.setEnabled(false);
        aceptar.setName("paceptar"); // NOI18N
        aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarActionPerformed(evt);
            }
        });

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel11.setForeground(new java.awt.Color(240, 240, 240));
        jLabel11.setText("Planificacion de la Unidad.");
        jTaskPane1.add(jLabel11);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(editar, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(aceptar)
                    .addComponent(jButton1))
                .addGap(62, 62, 62))
            .addComponent(jTaskPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTaskPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(editar)
                        .addGap(18, 18, 18)
                        .addComponent(aceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleName("BPlanificacion");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void notaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_notaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_notaActionPerformed

    private void zonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zonaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_zonaActionPerformed

    private void examenfinalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_examenfinalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_examenfinalActionPerformed

    private void examenparcialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_examenparcialActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_examenparcialActionPerformed

    private void otrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_otrasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_otrasActionPerformed

    private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarActionPerformed
        // TODO add your handling code here:

        int cien=0;
        if ((this.nota.getText().isEmpty()==true) ||
            (this.otras.getText().isEmpty()==true) ||
            (this.zona.getText().isEmpty()==true) ||
            (this.examenfinal.getText().isEmpty()==true) ||
            (this.examenparcial.getText().isEmpty()==true)){
            JOptionPane.showMessageDialog(null,"Llene todos los campos");
        }

        try {
          int res = Integer.parseInt(this.nota.getText())
                +Integer.parseInt(this.otras.getText())
                +Integer.parseInt(this.zona.getText())
                +Integer.parseInt(this.examenfinal.getText())
                +Integer.parseInt(this.examenparcial.getText());
           cien = Integer.parseInt(this.otras.getText())
                +Integer.parseInt(this.zona.getText())
                +Integer.parseInt(this.examenfinal.getText())
                +Integer.parseInt(this.examenparcial.getText());

        }
        catch(Exception e){ //para que no ingrese letras en los campos 
            JOptionPane.showMessageDialog(null,"Llene los campos únicamente "
              +"con valores numéricos");
        }
        if (cien==100) {
            ingresar();
        }
        else{
            JOptionPane.showMessageDialog(null,"La Zona mas Examen Final"
                    + " mas Examen Parcial mas Otras Tareas no suman 100 pts");
        }
    }//GEN-LAST:event_aceptarActionPerformed

    private void editarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarActionPerformed
        // TODO add your handling code here:
        aceptar.setEnabled(true);
        nota.setEnabled(true);
        zona.setEnabled(true);
        examenfinal.setEnabled(true);
        examenparcial.setEnabled(true);
        otras.setEnabled(true);
      
    }//GEN-LAST:event_editarActionPerformed

    private void editarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_editarMouseClicked
        // TODO add your handling code here:
       
        
    }//GEN-LAST:event_editarMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        System.exit(0);//cerrar
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                aPlanificacion dialog = new aPlanificacion(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.JButton editar;
    private javax.swing.JTextField examenfinal;
    private javax.swing.JTextField examenparcial;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private com.l2fprod.common.swing.JTaskPane jTaskPane1;
    private javax.swing.JTextField nota;
    private javax.swing.JTextField otras;
    private javax.swing.JTextField zona;
    // End of variables declaration//GEN-END:variables

    private void ingresar() {
        //idPlanificacion,NotaAprobacion,Zona,ExamenFinal,ExamenParcial,Otros
        conexion cnx=conexion.ObtenerInstancia();
        EntityManagerFactory emf=cnx.ObtenerEMF();
        PlanificacionPersonalizada plan = new PlanificacionPersonalizada(emf);

        short id = 1;//(short) (plan.UltimoId()+1);
        Byte nota = Byte.valueOf(this.nota.getText());
        Float zona = Float.valueOf(this.zona.getText());
        Byte examenfinal = Byte.valueOf(this.examenfinal.getText());
        Byte examenparcial = Byte.valueOf(this.examenparcial.getText());
        short otros = Short.valueOf(this.otras.getText());
       

        Planificacion nueva = new Planificacion(id,nota,zona,examenfinal,examenparcial,otros);
                //(nota,zona,examenfinal,examenparcial,otros1);
        plan.create(nueva);

        JOptionPane.showMessageDialog(null,"Planificacion Ingresada");
    }

    public void cargardatos(){
        
    }
}
